﻿#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>

using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
int cnt[N]; // 计数排序
LL tmp[3]; // 标记需要合并的两个果⼦
queue<LL> q[3]; // q[1] q[2]

int read()
{
	int ret = 0;
	char ch = getchar();
	while (ch > '9' || ch < '0') ch = getchar();
	while (ch <= '9' && ch >= '0')
	{
		ret = 10 * ret + ch - '0';

		ch = getchar();
	}
	return ret;
}
int main()
{
	int n = read();
	for (int i = 1; i <= n; i++)
	{
		int x = read();
		cnt[x]++;
	}
	for (int i = 1; i < N; i++)
		while (cnt[i]--)
			q[1].push(i);


	LL ret = 0;
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j <= 2; j++)
		{
			if (q[2].empty() || (q[1].size() && q[2].front() > q[1].front()))
			{
				tmp[j] = q[1].front();
				q[1].pop();
			}
			else
			{
				tmp[j] = q[2].front();
				q[2].pop();
			}
		}
		ret += tmp[1] + tmp[2];
		q[2].push(tmp[1] + tmp[2]);
	}

	printf("%lld\n", ret);
	return 0;
}